package br.cin.ufpe.corba.namingservice;

import java.io.Serializable;

import br.cin.ufpe.corba.ObjectImpl;
import br.cin.ufpe.corba.ObjectRef;
import br.cin.ufpe.corba.namingservice.binding.BindingList;

public class NamingContextStub extends ObjectImpl implements NamingContextExt, Serializable {

	private static final long serialVersionUID = -7574433462520987932L;

	public NamingContextStub(ObjectRef objectRef) {
		super(objectRef);
	}

	public void bind(Name name, Object obj) {
		invoke("bind", 
				new String[] { Name.class.getCanonicalName(), Object.class.getCanonicalName() }, 
				new Object[] { name, obj }, false);
	}

	public void bind_context(Name name, NamingContext nc) {
		invoke("bind_context", 
				new String[] { Name.class.getCanonicalName(), NamingContext.class.getCanonicalName() }, 
				new Object[] { name, nc }, false);
	}

	public NamingContext bind_new_context(Name name) {
		return NamingContextHelper.narrow(invoke("bind_new_context", 
				new String[] { Name.class.getCanonicalName() }, 
				new Object[] { name }, true));
	}

	public void destroy() {
		invoke("destroy", new String[] {}, new Object[] {}, false);
	}

	public NamingContext new_context() {
		return NamingContextHelper.narrow(invoke("new_context", 
				new String[] { }, new Object[] { }, true));
	}

	public void rebind(Name name, Object obj) {
		invoke("rebind", 
				new String[] {Name.class.getCanonicalName(), Object.class.getCanonicalName()}, 
				new Object[] {name, obj}, false);
	}

	public void rebind_context(Name name, NamingContext nc) {
		invoke("rebind_context", 
				new String[] {Name.class.getCanonicalName(), NamingContext.class.getCanonicalName()}, 
				new Object[] {name, null}, false);
	}

	public ObjectRef resolve(Name name) {
		return (ObjectRef)invoke("resolve", 
				new String[] { Name.class.getCanonicalName() }, 
				new Object[] { name }, true);
	}

	public void unbind(Name name) {
		invoke("unbind", 
				new String[] { Name.class.getCanonicalName() },
				new Object[] { name }, false);
	}

	public BindingList list(int how_many) {
		return (BindingList) invoke("list", 
				new String[] { int.class.getCanonicalName() },
				new Object[] { how_many }, true);
	}

	public ObjectRef resolve_str(String name) throws NotFound, InvalidName {
		return resolve(to_name(name));
	}

	public Name to_name(String sname) throws InvalidName {
		return new Name(sname);
	}

	public String to_string(Name name) throws InvalidName {
		return name.toString();
	}

}
